import java.util.*;

class Solution {
    private List<List<Integer>> bigList = new LinkedList<>();
    public List<List<Integer>> fourSum(int[] nums, int target) {
        if(nums.length<4){
            return bigList;
        }


        Arrays.sort(nums);   //先对其进行排序
        for(int i=0;i<nums.length;){  //这个需要去重复的，要跳过连续的
            int tmp1 = target-nums[i];
            for(int j =i+1;j<nums.length;){  //这个也需要跳过连续相等的
                int tmp2 = tmp1-nums[j];
                int left=j+1;
                int right=nums.length-1;
                while(left<right){
                    if((nums[left]+nums[right])<tmp2){
                        left++;
                    }else if((nums[left]+nums[right])>tmp2){
                        right--;
                    }else{
                        List<Integer> list = new LinkedList<>();
                        list.add(nums[i]);
                        list.add(nums[j]);
                        list.add(nums[left]);
                        list.add(nums[right]);
                        bigList.add(list);
                        left++;
                        right--;
                        while(left<right&&nums[left]==nums[left-1]){
                            left++;
                        }
                        while(left<right&&nums[right]==nums[right+1]){
                            right--;
                        }
                    }


                }
                j++;
                while(j<nums.length&&nums[j]==nums[j-1]){
                    j++;
                }
            }
            i++;
            while(i<nums.length&&nums[i]==nums[i-1]){
                i++;
            }
        }
        return bigList;

    }

    public int minSubArrayLen(int target, int[] nums) {
        int left = 0;
        int right = 0;
        int sum = nums[0];
        int length = 0;
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        while(left<=right&&right<nums.length){
            if(sum<target){
                right++;
                if(right>nums.length-1){
                    break;
                }
                sum+=nums[right];
            }else {
                length=right-left;
                priorityQueue.add(length);
                sum = sum-nums[left];
                left++;
            }
        }
        if(right>nums.length-1&&left==0){
            return 0;
        }
        return (int)priorityQueue.poll();
    }

    public static int getMaxNoSame(char[] nums){
        int left = 0;
        int right = 0;
        int[] MaxSum = new int[nums.length];
        int k =0;
        HashSet<Character> set = new HashSet<>();

            for(right=0;right<nums.length;right++){
                boolean flag = set.add(nums[right]);
                if(right==nums.length-1){
                    MaxSum[k]=set.size();
                    k++;
                }
                if(flag==false){
                    MaxSum[k]=set.size();
                    k++;
                    while(left<right){
                        if(nums[left]==nums[right]){
                            set.remove(nums[left]);
                            set.add(nums[right]);
                            left++;
                            break;
                        }else{
                            set.remove(nums[left]);
                            left++;
                        }

                    }

                }
            }

        Arrays.sort(MaxSum);
        return MaxSum[MaxSum.length-1];
    }

    public static void main(String[] args) {
        char[] nums = new char[]{'a','a','b','a','a','b','!','b','b'};
        int max =getMaxNoSame(nums);
        System.out.println(max);
    }
    public static void main4(String[] args) {
        int[] nums = new int[]{1,1,1,1,1,1,1,1};
        Solution solution = new Solution();
        solution.minSubArrayLen(11,nums);
        System.out.println("111");
    }

    public static void main3(String[] args) {
        int[] nums = new int[]{1000000000,1000000000,1000000000,1000000000};
        Solution solution = new Solution();
        solution.fourSum(nums,-294967296);
        System.out.println(solution.bigList);
    }
}